package com.example.Holo.rework.services.implementation;

import com.example.Holo.rework.core.Part;
import com.example.Holo.rework.core.Payment;
import com.example.Holo.rework.dao.interfaces.IDaoFactory;
import com.example.Holo.rework.dao.interfaces.IPartDao;
import com.example.Holo.rework.dao.interfaces.IPaymentDao;
import com.example.Holo.rework.services.interfaces.IPartService;

import java.util.List;

public class PartService extends Service implements IPartService {

    public PartService(IDaoFactory daoFactory) {
        super(daoFactory);
    }

    @Override
    public long addPayment(Payment payment, List<Part> parts) {
        final IPaymentDao paymentDao = daoFactory.createPaymentDao();
        final IPartDao partDao = daoFactory.createPartDao();
        final long paymentId = paymentDao.addPayment(payment);
        for ( Part part : parts ) {
            part.setPaymentId(paymentId);
            partDao.addPart(part);
        }
        return 0;
    }
}
